package com.task.config;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @author jiafujun
 * 2020年01月21日 10:15:00
 */
@Component
public class WeChatMpConfig {

    @Autowired
    private WeChatConfig weChatConfig;

    @Bean
    public WxMpService wxMpService() {
        WxMpService wxMpService = new WxMpServiceImpl();
        wxMpService.setWxMpConfigStorage(wxMpConfigStorage());
        return wxMpService;
    }

    @Bean
    public WxMpConfigStorage wxMpConfigStorage() {
        WxMpConfigStorage wxMpConfigStorage = new WxMpDefaultConfigImpl();
        ((WxMpDefaultConfigImpl) wxMpConfigStorage).setAppId(weChatConfig.getAppId());
        ((WxMpDefaultConfigImpl) wxMpConfigStorage).setSecret(weChatConfig.getAppSecret());
        return wxMpConfigStorage;
    }
}
